from django.db import models


# ---------------------------------------文件部分----------------------------------------------
# 文件夹表
class BankFile(models.Model):
    file_id = models.AutoField(primary_key=True, verbose_name='文件夹id')
    title = models.CharField(max_length=255, blank=True, null=True, verbose_name='文件夹名称')
    grade = models.IntegerField(default='0', verbose_name='直属库')  # 级别0为默认
    front_id = models.IntegerField(null=True, blank=True, verbose_name='前导的文件夹id')
    number = models.IntegerField(null=True, blank=True, verbose_name='同级文件编号')
    course_id = models.IntegerField(null=True, blank=True, verbose_name='所属课程id')
    create_time = models.DateTimeField(blank=True, null=True, verbose_name='创建时间')
    creator = models.CharField(max_length=48, verbose_name='创建者id')
    file_type = models.CharField(max_length=30, null=True, blank=True,
                                 verbose_name='文件夹属于某一库下')  # resource|question|homework|task

    class Meta:
        managed = 'True'
        db_table = 'bank_file'


# ----------------------------------------用户信息---------------------------------------------
# 用户表
class User(models.Model):
    SEX_CHOICE = [
        (0, '男'),
        (1, '女'),
    ]

    POWER_CHOICE = [
        (0, '超级管理员'),
        (1, '管理员'),
        (2, '教师'),
        (3, '志愿者'),
        (4, '用户'),
    ]

    user_id = models.OneToOneField(to='Password', to_field='user_id', on_delete=models.CASCADE, primary_key=True,
                                   verbose_name='已注册用户')
    real_name = models.CharField(max_length=20, null=True, blank=True, verbose_name='真实姓名')
    nick = models.CharField(max_length=24, blank=True, null=True, verbose_name='昵称')
    email = models.EmailField(blank=True, null=True, verbose_name='邮箱')
    submit = models.IntegerField(default=0, verbose_name='提交数量')
    solved = models.IntegerField(default=0, verbose_name='解决数量')
    defunct = models.BooleanField(default=0, verbose_name='是否隐藏')
    ip = models.GenericIPAddressField(verbose_name='ip地址')
    access_time = models.DateTimeField(blank=True, null=True, verbose_name='登陆时间')
    reg_time = models.DateTimeField(blank=True, null=True, verbose_name='注册时间')
    school = models.CharField(max_length=20, verbose_name='学校')
    score = models.IntegerField(default=0, verbose_name='得分')
    sex = models.IntegerField(choices=SEX_CHOICE, verbose_name='性别')
    role_pri = models.IntegerField(choices=POWER_CHOICE, default='4', verbose_name='权限')
    is_delete = models.BooleanField(default=0, verbose_name='保护')

    class Meta:
        managed = True
        db_table = 'user'


# 用户ip
class UserIp(models.Model):
    user_id = models.CharField(max_length=48, verbose_name='用户编号')
    start_time = models.DateTimeField(verbose_name='开始时间')
    during = models.IntegerField(default=0, verbose_name='限制时长')

    class Meta:
        managed = True
        db_table = 'user_ip'


# 登录日志
class LoginLog(models.Model):
    user_id = models.CharField(max_length=48, verbose_name='用户账号')
    ip = models.GenericIPAddressField(null=True, blank=True, verbose_name='登录IP')
    time = models.DateTimeField(null=True, blank=True, verbose_name='登入时间')
    login_way = models.CharField(max_length=256, blank=True, null=True, verbose_name='登录方法')

    class Meta:
        managed = True
        db_table = 'login_log'


# 密码表
class Password(models.Model):
    user_id = models.CharField(max_length=32, primary_key=True, verbose_name='学号/工号')
    password = models.CharField(max_length=64, verbose_name='密码')

    class Meta:
        managed = True
        db_table = 'password'


# ----------------------------------------班级部分-------------------------------------
# 班级表
class Class(models.Model):
    class_id = models.AutoField(primary_key=True, verbose_name='班级id')
    class_name = models.CharField(max_length=20, verbose_name='班级名称')
    class_score = models.IntegerField(default=0, verbose_name='班级得分')
    teachers = models.CharField(max_length=192, null=True, blank=True, verbose_name='班级老师')
    creator = models.CharField(max_length=48, verbose_name='创建者')
    college = models.CharField(max_length=20, null=True, blank=True, verbose_name='学院名称')
    create_date = models.DateTimeField(verbose_name='创建日期')
    type = models.CharField(max_length=10, verbose_name='班级类型')  # 是否要进行限制

    class Meta:
        managed = True
        db_table = 'class'


# 班级用户
class ClassUser(models.Model):
    num_id = models.AutoField(primary_key=True, verbose_name='序号')
    class_id = models.IntegerField(verbose_name='班级ID')
    user_id = models.CharField(max_length=48, verbose_name='用户ID')

    class Meta:
        managed = True
        db_table = 'class_user'


# -----------------------------------------题目部分------------------------------------ #
# 问题表
class Problems(models.Model):
    problem_id = models.AutoField(primary_key=True, verbose_name='问题id')
    title = models.CharField(max_length=200, verbose_name='标题')
    description = models.TextField(blank=True, null=True, verbose_name='描述')
    input = models.TextField(blank=True, null=True, verbose_name='输入')
    output = models.TextField(blank=True, null=True, verbose_name='输出')
    sample_input = models.TextField(blank=True, null=True, verbose_name='样例输入')
    sample_output = models.TextField(blank=True, null=True, verbose_name='样例输出')
    spj = models.CharField(max_length=1, default=0, verbose_name='特判')
    hint = models.TextField(blank=True, null=True, verbose_name='提示')
    source = models.CharField(max_length=100, blank=True, null=True, verbose_name='来源')
    in_data = models.DateTimeField(blank=True, null=True, verbose_name='创建时间')
    time_limit = models.IntegerField(default=1000, verbose_name='时间限制')
    memory_limit = models.IntegerField(default=128, verbose_name='空间限制')
    defunct = models.BooleanField(max_length=1, default=0, verbose_name='是否隐藏')
    accepted = models.IntegerField(default=0, verbose_name='通过数')
    submit = models.IntegerField(default=0, verbose_name='提交数')
    # solved = models.IntegerField(blank=True, null=True)          # 解答（未用）
    type = models.CharField(max_length=100, blank=True, null=True, verbose_name='知识点')
    difficulty = models.IntegerField(blank=True, null=True, verbose_name='难度')
    creator = models.CharField(max_length=48, blank=True, null=True, verbose_name='创建者')
    is_delete = models.BooleanField(default=0, verbose_name='题目保护')

    class Meta:
        managed = True
        db_table = 'problems'


# 提交问题表 
class Solution(models.Model):
    solution_id = models.AutoField(primary_key=True, verbose_name='解决方式自动生成')
    problem_id = models.IntegerField(verbose_name='问题id')
    user_id = models.CharField(max_length=48, verbose_name='用户id')
    time = models.IntegerField(verbose_name='运行时间')
    memory = models.IntegerField(verbose_name='内存使用')
    in_date = models.DateTimeField(verbose_name='提交日期')
    result = models.SmallIntegerField(verbose_name='提交结果')
    language = models.IntegerField(verbose_name='所用语言')
    ip = models.CharField(max_length=46, blank=True, null=True, verbose_name='ip地址')
    contest_id = models.IntegerField(blank=True, null=True, verbose_name='比赛id')
    valid = models.IntegerField(blank=True, null=True, verbose_name='')
    num = models.IntegerField(blank=True, null=True, verbose_name='')
    code_length = models.IntegerField(blank=True, null=True, verbose_name='代码长度')
    judgetime = models.DateTimeField(blank=True, null=True, verbose_name='判题时间')
    pass_rate = models.DecimalField(max_digits=3, decimal_places=2, verbose_name='通过率')
    lint_error = models.IntegerField(blank=True, null=True)
    judger = models.CharField(max_length=16, verbose_name='判题机')
    upload_system = models.CharField(max_length=20, blank=True, null=True, verbose_name='判题系统')

    class Meta:
        managed = True
        db_table = 'solution'


# 收藏表
class Collection(models.Model):
    collect_id = models.AutoField(primary_key=True)  # 创建收藏id
    user_id = models.CharField(max_length=48, blank=True, null=True)  # 用户id
    problem_id = models.IntegerField(blank=True, null=True)  # 问题id

    class Meta:
        managed = True
        db_table = 'collection'


# 用户上传的代码
class SourceCode(models.Model):
    solution_id = models.IntegerField(primary_key=True)
    source = models.TextField()

    class Meta:
        managed = True
        db_table = 'source_code'


# 上传代码的用户
class SourceCodeUser(models.Model):
    solution_id = models.IntegerField(primary_key=True)  # 成绩ID
    source = models.TextField()  # 来源

    class Meta:
        managed = True
        db_table = 'source_code_user'


# 编译错误表
class CompileieInfo(models.Model):
    solusion_id = models.IntegerField()
    error = models.TextField(blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'compileieinfo'


# 运行错误表
class RuntimeInfo(models.Model):
    solusion_id = models.IntegerField()
    error = models.TextField(blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'runtimeinfo'


# 判重表
class Sim(models.Model):
    s_id = models.IntegerField()
    sim_s_id = models.IntegerField(blank=True, null=True)
    sim = models.IntegerField(blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'sim'


# 用户自测表
class CustomInput(models.Model):
    solution_id = models.IntegerField()  # 提交答案ID
    input_text = models.TextField()  # 提交内容

    class Meta:
        managed = True
        db_table = 'custominfo'


# 问题标签
class ProblemTag(models.Model):
    tag_name = models.CharField(max_length=48)  # 标签名
    problem_id = models.IntegerField(null=True, blank=True)  # 问题id

    class Meta:
        managed = True
        db_table = 'problem_tag'


# 问题来源
class ProblemSource(models.Model):
    source_name = models.CharField(max_length=48)
    problem_id = models.IntegerField(null=True, blank=True)  # 问题id

    class Meta:
        managed = True
        db_table = 'problem_source'


# ---------------------------------------新闻部分--------------------------------------#
# 新闻表
class News(models.Model):
    news_id = models.AutoField(primary_key=True)  # 新闻id
    user_id = models.CharField(max_length=48, blank=True, null=True)  # 用户id
    title = models.CharField(max_length=50)  # 标题
    content = models.TextField()  # 内容
    time = models.DateTimeField()  # 时间
    importance = models.IntegerField(default=0)  # 优先级
    defunct = models.BooleanField(default=0)  # 是否失效
    image = models.CharField(max_length=2)  # 图片
    image_path = models.CharField(max_length=80)  # 图片地址

    class Meta:
        managed = True
        db_table = 'news'


# -----------------------------------------气球部分------------------------------------#
# 气球表
class Ballon(models.Model):
    ballon_id = models.AutoField(primary_key=True)  # 气球id
    user_id = models.CharField(max_length=48)  # 用户id
    sid = models.IntegerField()  # 提交id
    cid = models.IntegerField()  # 比赛id
    pid = models.IntegerField()  # 问题id
    status = models.SmallIntegerField()  # 状态

    class Meta:
        managed = True
        db_table = 'ballon'


# 打印表
class Printer(models.Model):
    printer_id = models.AutoField(primary_key=True)
    user_id = models.CharField(max_length=48)
    in_date = models.DateTimeField()
    status = models.SmallIntegerField()
    worktime = models.DateTimeField(blank=True, null=True)
    printer = models.CharField(max_length=16)
    content = models.TextField(blank=True, null=True)

    class Meta:
        managed = True
        db_table = 'printer'


# ---------------------------------------竞赛部分--------------------------------------#
# 比赛
class Contest(models.Model):
    PRIVATE_CHOICE = (
        (0, 'public'),
        (1, 'private'),
        (2, 'work'),
    )

    contest_id = models.AutoField(primary_key=True)  # 比赛ID
    title = models.CharField(max_length=255, blank=True, null=True)  # 比赛名称
    start_time = models.DateTimeField(blank=True, null=True)  # 开始时间
    end_time = models.DateTimeField(blank=True, null=True)  # 结束时间
    defunct = models.BooleanField(default=1)  # 是否结束 N/Y
    description = models.TextField(blank=True, null=True)  # 描述 
    private = models.IntegerField(choices=PRIVATE_CHOICE)  # 比赛类型 0为公开 1为私有 2为作业
    langmask = models.IntegerField(default=1)  # 编程语言类型
    password = models.CharField(max_length=16, blank=True, null=True)  # 竞赛密码
    creator = models.CharField(max_length=48, blank=True, null=True)  # 创建者

    # nick = models.CharField(max_length=24, blank=True, null=True)  # 昵称

    class Meta:
        managed = True
        db_table = 'contest'


# 比赛问题
class ContestProblem(models.Model):
    problem_id = models.IntegerField()  # 问题ID
    contest_id = models.IntegerField(blank=True, null=True)  # 比赛ID
    title = models.CharField(max_length=200, blank=True, null=True)  # 标题
    num = models.IntegerField()  # 题目序号

    class Meta:
        managed = True
        db_table = 'contest_problem'


# 竞赛用户
class ContestUser(models.Model):
    contest_id = models.IntegerField(blank=True, null=True)  # 竞赛id
    user_id = models.CharField(max_length=48, blank=True, null=True)  # 用户id
    team_id = models.IntegerField(blank=True, null=True)  # 团队id
    contest_user = models.CharField(max_length=48, blank=True, null=True)  # 生成比赛账号
    grades = models.CharField(max_length=48, null=True, blank=True)  # 获奖等级
    auditing = models.BooleanField(default='0')  # 审核状态

    class Meta:
        managed = True
        db_table = 'contest_user'


# ---------------------------------------论坛模块----------------------------------#
# 论坛主板表
class FormSection(models.Model):
    fs_id = models.AutoField(primary_key=True)  # 论坛id
    forum_section_title = models.CharField(max_length=256, null=True, blank=True)  # 论坛标题
    description = models.CharField(max_length=256, null=True, blank=True)  # 论坛说明
    creator_id = models.CharField(max_length=48)  # 创建者id
    creator_nick = models.CharField(max_length=48)  # 创建者昵称
    create_time = models.DateTimeField()  # 创建时间
    post_num = models.IntegerField(default=0)  # 帖子数量
    click_num = models.IntegerField(default=0)  # 点击数量
    prefix_num = models.IntegerField(null=True, blank=True)  # 前置编号
    section_type = models.CharField(max_length=100)  # 模板主次类型
    function = models.BooleanField(default=0)  # 是否隐藏
    is_delete = models.BooleanField(default=0)  # 是否删除
    class_id = models.IntegerField(null=True, blank=True)  # 班级id
    class_title = models.CharField(max_length=50, null=True, blank=True)  # 班级名

    class Meta:
        managed = True
        db_table = 'form_section'

    # 帖子表


class Post(models.Model):
    post_id = models.AutoField(primary_key=True)  # 帖子ID
    fs_id = models.IntegerField(blank=True, null=True)  # 对应版块ID
    post_title = models.CharField(max_length=255)  # 帖子标题
    content = models.TextField()  # 帖子内容
    creator = models.CharField(max_length=48)  # 创建者
    creator_nick = models.CharField(max_length=48)  # 创建者昵称
    creator_time = models.DateTimeField()  # 创建时间
    likes_num = models.IntegerField(default=0)  # 点赞数量
    comment_num = models.IntegerField(default=0)  # 评论数量
    collect_num = models.IntegerField(default=0)  # 收藏数量
    reasons = models.TextField(blank=True, null=True)  # 不通过理由
    is_pass = models.BooleanField(default=0)  # 是否审核通过 1/0
    function = models.BooleanField(default=0)  # 是否失效 1/0
    is_delete = models.BooleanField(default=0)  # 是否删除 1/0

    class Meta:
        managed = True
        db_table = 'post'


# 帖子的点赞收藏表
class PostUser(models.Model):
    id = models.AutoField(primary_key=True)  # 表ID
    post_id = models.IntegerField(blank=True, null=True)  # 帖子ID
    user_id = models.CharField(max_length=48)  # 用户
    is_likes = models.BooleanField(default=0)  # 是否点赞 Y/N
    is_collect = models.BooleanField(default=0)  # 是否收藏 Y/N

    class Meta:
        managed = True
        db_table = 'post_user'


# 回复
class Reply(models.Model):
    reply_id = models.AutoField(primary_key=True)  # ID
    post_id = models.IntegerField(blank=True, null=True)  # 对应帖子ID
    fs_id = models.IntegerField(blank=True, null=True)  # 所属版块ID
    # post_title = models.CharField(max_length=255)  # 回复标题
    content = models.TextField()  # 回复内容
    creator = models.CharField(max_length=48)  # 创建者
    creator_nick = models.CharField(max_length=48)  # 创建者昵称
    creator_time = models.DateTimeField()  # 创建时间
    function = models.BooleanField(default=0)  # 是否失效 Y/N
    is_delete = models.BooleanField(default=0)  # 是否删除 Y/N
    to_reply_id = models.IntegerField(default=-1)  # 回复某个回复的ID，默认-1，则回复的是帖子

    class Meta:
        managed = True
        db_table = 'reply'


# ---------------------------------------关卡模块----------------------------------#
# 关卡
class Level(models.Model):
    level_id = models.AutoField(primary_key=True)  # 关卡ID
    title = models.CharField(max_length=255, blank=True, null=True)  # 标题
    description = models.TextField(blank=True, null=True)  # 描述
    level_pre = models.CharField(max_length=50, blank=True, null=True)  # 先导关卡，逗号分隔
    pass_num = models.IntegerField(blank=True, null=True)  # 通过人数
    type = models.IntegerField(blank=False, null=False, default=1)  # 类型 1关卡 2关卡大类
    num = models.IntegerField(blank=False, null=False, default=0)  # 编号
    front_id = models.IntegerField(blank=False, null=False)  # 不允许为空，属于那个大类
    creator = models.CharField(max_length=32, blank=False, null=False)  # 创建者ID
    nick = models.CharField(max_length=24, blank=True, null=True, verbose_name='昵称')  # 创建者昵称
    defunct = models.CharField(max_length=4, blank=True, null=False, verbose_name='N')  # 是否不使用 N否，Y是

    class Meta:
        managed = True
        db_table = 'level'


class LevelProblem(models.Model):
    problem_id = models.IntegerField(blank=False, null=False, default=0)  # 问题ID
    level_id = models.IntegerField(blank=False, null=False, default=0)  # 关卡ID
    num = models.IntegerField(blank=False, null=False, default=0)  # 序号

    class Meta:
        managed = True
        db_table = 'level_problem'


# 过关者
class LevelPass(models.Model):
    level_id = models.IntegerField(blank=True, null=True)  # 关卡ID
    user_id = models.CharField(max_length=48)  # 用户ID
    pass_time = models.DateTimeField(blank=True, null=True)  # 通过日期

    class Meta:
        managed = True
        db_table = 'level_pass'


class LevelProblemSubmit(models.Model):
    level_id = models.IntegerField(blank=True, null=True)  # 关卡ID
    user_id = models.CharField(max_length=48)  # 用户ID
    submit_time = models.DateTimeField(blank=True, null=True)  # 提交
    type = models.IntegerField(blank=False, null=False, default=1)  # 类型 1通关 2错误
    solution_id = models.IntegerField()  # 提交id

    class Meta:
        managed = True
        db_table = 'level_problem_submit'


class Scratch(models.Model):
    author_id = models.CharField(max_length=32, verbose_name='作者ID')
    teacher_id = models.CharField(max_length=32, null=True, blank=True, verbose_name='课堂作业时所在的班级老师')
    state = models.SmallIntegerField(default='0', verbose_name='项目状态：未发布0、已发布1、开源2')
    recommented = models.SmallIntegerField(default='0', verbose_name='是否被推荐：0未被推荐，1已被推荐')
    view_count = models.IntegerField(default='0', verbose_name='被浏览次数')
    like_count = models.IntegerField(default='0', verbose_name='点赞次数')
    favo_count = models.IntegerField(default='0', verbose_name='被收藏次数')
    time = models.DateTimeField(null=True, blank=True, verbose_name='时间')
    title = models.CharField(max_length=32, default='Scratch新项目', verbose_name='标题')
    description = models.CharField(max_length=255, null=True, blank=True, verbose_name='描述')
    src = models.TextField(null=True, blank=True, verbose_name='源代码')

    class Meta:
        managed = True
        db_table = 'scratch'


class ScratchFavo(models.Model):
    user_id = models.CharField(max_length=32, verbose_name='用户ID')
    project_id = models.IntegerField(verbose_name='项目ID')
    time = models.DateTimeField(null=True, blank=True, verbose_name='时间')

    class Meta:
        managed = True
        db_table = 'scratch_favo'


class ScratchLike(models.Model):
    user_id = models.CharField(max_length=32, verbose_name='用户ID')
    project_id = models.IntegerField(verbose_name='项目ID')
    time = models.DateTimeField(null=True, blank=True, verbose_name='时间')

    class Meta:
        managed = True
        db_table = 'scratch_like'


# ---------------------------------------学院模块----------------------------------#
# 学院
class College(models.Model):
    college_id = models.AutoField(primary_key=True)  # 学院ID
    college_name = models.CharField(max_length=100)  # 学院名称

    class Meta:
        managed = True
        db_table = 'college'


# ---------------------------------------班级课程模块----------------------------------
# 课程表
class Courses(models.Model):
    course_id = models.AutoField(primary_key=True)  # 课程id
    title = models.CharField(max_length=36)  # 课程名称
    explain = models.TextField(blank=True, null=True)  # 课程介绍
    photo_add = models.CharField(max_length=255, blank=True, null=True)  # 封面图片地址
    evaluation_num = models.IntegerField(default=0)  # 评价数量
    view_num = models.IntegerField(default=0)  # 查看课程数量
    browse_num = models.IntegerField(default=0)  # 浏览数量
    member_num = models.IntegerField(default=0)  # 成员人数
    create_date = models.DateTimeField(blank=True, null=True)  # 创建时间
    defunct = models.BooleanField(default=0)  # 是否失效
    status = models.CharField(max_length=20)  # 状态
    creator = models.CharField(max_length=48, null=True, blank=True)  # 创建者

    class Meta:
        managed = True
        db_table = 'courses'


# 课程班级
class CourseClass(models.Model):
    course_class_id = models.AutoField(primary_key=True)
    course_id = models.IntegerField()  # 课程ID
    class_id = models.IntegerField()  # 班级ID

    class Meta:
        managed = True
        db_table = 'course_class'


# 课程类型
# class Course_type(models.Model):
#     grade_choice = (                                                                # 课程类型等级限制
#         (1, ''),
#         (2, ''),
#     )
#     # type_id = models.IntegerField()                                                 # 主键及外键约束字段
#     type_name = models.CharField(max_length=40, null=True)                          # 类型名字
#     create_time = models.DateTimeField()                                                # 创建日期
#     creator = models.IntegerField()                                                 # 创建者的外键id
#     count = models.IntegerField()                                                   # 该类型的课程总数
#     grade = models.IntegerField(choices=grade_choice)                               # 分级类型
#     front_id = models.IntegerField(null=True)                                                # 前置登记，默认无前置

#     class Meta:
#         managed = False
#         db_table = 'course_type'


# # 普通课程班级表
# class course_common_class(models.Model):
#     class_id = models.AutoField()   #班级id
#     class_name = models.CharField(max_length=255)   #班级名称
#     explain = models.TextField(blank=True, null=True)   #班级说明
#     create_time = models.DateTimeField(blank=True, null=True)   #创建时间
#     teacher = models.CharField(max_length=48)   #教师id
#     creator = models.CharField(max_length=48)   #创建者id
#     remask = models.CharField(max_length=255, blank=True, null=True)    #备注
#     member_num = models.IntegerField(blank=True, null=True) #班级人数
#     defunct = models.IntegerField(max_length=1, blank=True, null=True) #是否失效,1失效
#     allowed_quit = models.IntegerField(blank=True, null=True)   #是否允许退出 默认1允许
#     allowed_join = models.IntegerField(blank=True, null=True)   #是否允许加入 默认1允许


# # 普通班级成员
# class common_class_member(models.Model):
#     member_id = models.IntegerField()   #成员id
#     class_id = models.IntegerField()    #所属行政班级id
#     class_name = models.CharField(max_length=50)    #班级id
#     member = models.CharField(max_length=48)    #成员id
#     remask = models.CharField(max_length=255, blank=True, null=True)    #备注
#     nick = models.CharField(max_length=50, blank=True, null=True)   #昵称
#     add_user = models.CharField(max_length=48)  #添加的用户账号
#     add_time = models.DateTimeField(blank=True, null=True)  #添加时间
#     defunct = models.IntegerField(blank=True, null=True)    #是否失效1为失效
#     star = models.IntegerField(blank=True, null=True)   #星级值0-5
#     update_time = models.DateTimeField(blank=True, null=True)   #修改信息日期


# # 课程成员
# class course_member(models.Model):
#     member_id = models.AutoField()  # 成员ID
#     course_id = models.IntegerField() #所属课程ID 
#     nick = models.CharField(max_length=48, blank=True, null=True)  # 昵称
#     user = models.IntegerField()  #用户ID
#     inviter = models.IntegerField(blank=True, null=True)  # 邀请者ID
#     add_time = models.DateTimeField()  # 创建时间
#     add_user = models.IntegerField(blank=True, null=True)  # 添加该用户的用户，自己则自己
#     add_type = models.CharField(max_length=30)  # 加入方式 self|teacher|invite
#     recommend = models.IntegerField(blank=True, null=True)  # 是否设置为推荐 1为是 0为否
#     recommend_time = models.DateTimeField(blank=True, null=True)  #  设置为推荐的时间
#     remarks = models.CharField(max_length=255, blank=True, null=True)  # 备注
#     belong_class = models.IntegerField(blank=True, null=True)  # 所属于课程班级，0为默认没有班级，直属课程
#     update_time = models.DateTimeField(blank=True, null=True)  # 更新时间


# # 课程收藏
# class course_collection(models.Model):
#     collection_id = models.IntegerField()  # 收藏ID
#     course_id = models.IntegerField()  # 课程ID
#     creater = models.IntegerField()  # 收藏者ID
#     create_time = models.DateTimeField(blank=True, null=True)  # 创建时间


# # 课程评价
# class course_evaluation(models.Model):
#     evaluation_id = models.AutoField()  # 评价ID
#     creator = models.IntegerField()  # 创建者ID
#     course_id = models.IntegerField()  # 所评价的课程编号
#     content = models.TextField()  # 课程评价
#     create_time = models.DateTimeField(blank=True, null=True)  # 创建时间
#     score = models.IntegerField(blank=True, null=True)  # 分数 1-10
#     defunct = models.CharField(max_length=1, blank=True, null=True)  # 是否失效 1失效
#     nick = models.CharField(max_length=50)  # 昵称


# # 课程新闻
# class course_new(models.Model):
#     new_id = models.AutoField()  # 新闻id
#     title = models.CharField(max_length=80)  # 新闻标题
#     content = models.TextField()  # 新闻内容
#     creator = models.IntegerField()  # 创建者
#     create_time = models.DateTimeField()  # 创建时间
#     update_time = models.DateTimeField(blank=True, null=True)  # 更新时间
#     view_num = models.IntegerField(blank=True, null=True)  # 查看人数
#     support_num = models.IntegerField(blank=True, null=True)  # 点赞人数
#     nick = models.CharField(max_length=50)  # 昵称
#     num = models.IntegerField()  # 显示序号


# # 章节表
# class chapter(models.Model):
#     chapter_id = models.AutoField() #章id
#     course_id = models.IntegerField()   #所属课程id
#     title = models.CharField(max_length=255)    #章节名称
#     grade = models.IntegerField()   #章节级别
#     number = models.IntegerField()  #章节编号
#     front_id = models.IntegerField()    #前导章节
#     type = models.CharField(max_length=255) #类型chapter章section节
#     creator = models.CharField(max_length=48)   #创建者id
#     create_time = models.DateTimeField(blank=True, null=True)   #创建时间
#     defunct = models.CharField(max_length=1, blank=True, null=True) #是否失效,1失效
#     status = models.CharField(max_length=20, blank=True, null=True) #状态 published|unpublished|create


# # 章节类容内容
# class chapter_content(models.Model):
#     content_id = models.AutoField()    #内容id
#     course_id = models.IntegerField()     #所属课程id
#     chapter_id = models.IntegerField()    #所属章节id
#     content = models.TextField(blank=True, null = True)   #内容
#     creator = models.CharField(max_length=48)   #创建者
#     creator_time = models.DateTimeField(blank=True, null = True)   #创建时间
#     defunct = models.IntegerField(max_length=1, blank=True, null=True)    # 是否失效 1失效


# # 课件
# class Courseware(models.Model):
#     FILE_TYPE_CHOICE=(
#         (0, 'file'),
#         (1, 'audio'),
#         (2, 'video'),
#         (3, 'img')

#     )
#     # courseware_id = models.AutoField(primary_key=True)                                 # 课件id                      
#     title = models.CharField(max_length=255)                                             # 标题
#     filename = models.CharField(max_length=255)                                          # 文件名称
#     remarks = models.CharField(max_length=255, blank=True, null=True)                    # 备注
#     # file_type = models.CharField(max_length=10)                                          # 课件类型   
#     link = models.CharField(max_length=255)                                              # 连接地址                                             
#     course_id = models.IntegerField()                                                    # 所属课程id
#     chapter_id = models.IntegerField()                                                   # 章节id
#     file_size = models.IntegerField()                                                    # 文件大小
#     upload_time = models.DateTimeField(blank=True, null=True)                            # 上传时间
#     creator = models.CharField(max_length=48)                                            # 创建者id
#     defunct = models.IntegerField(choices=IS_DELETE_CHOICE)                              # 是否失效 
#     # allow_download = models.IntegerField(blank=True, null=True)                          # 是否允许下载

#     class Meta:
#         managed = False
#         db_table = 'courseware'


# # 课件文件
# class resourse_bank(models.Model):
#     resourse_id = models.AutoField() #课件id
#     filename = models.CharField(max_length=255) #文件名称
#     type = models.CharField(max_length=10)  #课件类型
#     link = models.CharField(max_length=255) #链接
#     course_id = models.IntegerField()   #所属课程id
#     file_size = models.IntegerField()   #文件大小
#     upload_time = models.DateTimeField(blank=True, null = True) #上传时间 
#     cretor = models.CharField(max_length=48)    #创建者id
#     defunct = models.IntegerField(max_length=1, blank=True, null=True)  #是否失效 1失效
#     file_id = models.IntegerField(blank=True, null=True)    #所属分类文件id,默认0从属资源库


# # 推荐表
# class course_commend(models.Model):
#     cr_id = models.IntegerField()                                   # 课程推荐
#     course_id = models.IntegerField()                               # 课程id
#     creator = models.IntegerField()                                 # 创建者
#     create_time = models.DateTimeField()                            # 创建时间
#     defunct = models.BooleanField()                                 # 是否失效
#     display_num = models.IntegerField()                             # 显示顺序
#     nick = models.CharField(max_length=50)                          # 创建者昵称


# # 课程问题库
# class course_question_bank(models.Model):
#     question_id = models.IntegerField()  # 问题id
#     content = models.TextField()  # 题面
#     question_type = models.CharField(max_length=30)  # 题目类型
#     option = models.TextField()  # 选项 使用|分割
#     anwser = models.TextField()  # 答案，使用json字符存储
#     course_id = models.IntegerField()  # 所属课程
#     file_id = models.IntegerField()  # 所属文件夹  默认0，直属课程题库
#     allowed_change = models.IntegerField()  # 是否允许答案互换，针对多选和多个填空，1允许
#     upload_time = models.DateTimeField()  # 上传时间，默认时间戳
#     upload_user = models.IntegerField()  # 上传者
#     last_update = models.DateTimeField()  # 最好一次修改时间
#     isDelete = models.IntegerField()  # 是否删除 1删除


# # 课程问题
# class course_question(models.Model):
#     cq_id = models.AutoField()  # 课程问题id
#     course_id = models.IntegerField()  # 所属课程id
#     content = models.TextField()  # 提问内容
#     creator = models.IntegerField()  # 创建者
#     reply_question = models.IntegerField()  # 回复的ID，0为主贴
#     create_time = models.DateTimeField(blank=True, null=True)  # 发表时间
#     type = models.CharField(max_length=30, blank=True, null=True)  # 发表时间
#     reply_user = models.IntegerField(blank=True, null=True)  # 回复的用户，允许null
#     status = models.CharField(max_length=30, blank=True, null=True)  # 状态 pulished|unpublished
#     defunct = models.IntegerField(blank=True, null=True)  # 是否失效 1失效


# ---------------------------------------课程作业部分--------------------------------------#
# 作业表
# class Task(models.Model):

#     TYPE_CHOICE = (
#         (0, 'exam'),
#         (1, 'homework'),
#         (2, 'test')
#     )

#     task_id = models.AutoField(primary_key=True)                    # 测试，考试，作业编号
#     title = models.CharField(max_length=50)                         # 检测名称
#     explain = models.TextField(blank=True, null=True)                       # 说明
#     creator = models.CharField(max_length=48, blank=True, null=True)                                # 创建者
#     create_time = models.DateTimeField()                            # 创建时间
#     type = models.IntegerField(choices = TYPE_CHOICE)                         # task类型 exam|homework|test:考试|作业|检测
#     begin_time = models.DateTimeField()                             # 开始时间
#     end_time = models.DateTimeField()                               # 结束时间
#     course_id = models.IntegerField(blank=True, null=True)                               # 所属课程id
#     chapter_id = models.IntegerField(blank=True, null=True)                              # 所属章节id
#     status = models.CharField(max_length=50)                        # 状态 create|published|unpublished
#     score = models.IntegerField()                                   # 考试总分
#     defunct = models.BooleanField(default=1)                                 # 是否失效
#     judge_way = models.CharField(max_length=20)                     # 判题方法 hand|machinem|mixing
#     file_id = models.IntegerField()                                 # 所属课程文件id，默认0只属于试卷库
#     make_way = models.CharField(max_length=20)                      # 创建方式 random|copy|hand
#     belong_class = models.IntegerField(default = 0)                            # 考试所属班级id，默认0，所有班级都可参加

#     class Meta:
#         managed = True
#         db_table = 'task'


# # task问题表
# class Task_question(models.Model):
#     tq_id = models.AutoField(primary_key=True)                               # tq——id
#     task_id = models.IntegerField()                                 # 论坛id
#     question_id = models.IntegerField()                             # 问题id
#     creator = models.CharField(max_length=48, blank=True, null=True)                       # 创建者
#     add_time = models.DateTimeField(blank=True, null=True)                      # 添加时间
#     score = models.DecimalField(max_digits=10, decimal_places=0)                      # 得分

#     class Meta:
#         managed = True
#         db_table = 'task_question'


# # 作业问题描述
# class Task_question_distribution(models.Model):
#     id = models.AutoField(primary_key=True)                                                          # 编号id
#     task_id = models.IntegerField()                                                     # 所属task_id
#     single_num = models.IntegerField()                                                    # 单选题数量
#     single_score = models.DecimalField(max_digits=5, decimal_places=2)                          # 单选题分数
#     multiple_num = models.IntegerField()                                                  # 多选题数量
#     multiple_score = models.DecimalField(max_digits=5, decimal_places=2)                 # 多选题分数
#     fill_num = models.IntegerField()                                                      # 填空题数量
#     fill_score = models.DecimalField(max_digits=5, decimal_places=2)                     # 填空题分数
#     program_num = models.IntegerField()                                                   # 程序题数量
#     program_score = models.DecimalField(max_digits=5, decimal_places=2)                  # 程序题分数
#     judge_sum = models.IntegerField()                                                     # 判断题数量
#     judge_score = models.DecimalField(max_digits=5, decimal_places=2)                    # 判断题数量
#     multiple_fill_sum = models.IntegerField()                                             # 多项填空题数量
#     multiple_fill_score = models.DecimalField(max_digits=5, decimal_places=2)              # 多项填空题分数
#     subjective_num = models.IntegerField()                                                # 主观题数量
#     subjective_score = models.DecimalField(max_digits=5, decimal_places=2)               # 主观题分数
#     sum_score = models.DecimalField(max_digits=8, decimal_places=2)                      # 总分
#     sum_num = models.IntegerField()                                                       # 总数量

#     class Meta:
#         managed = True
#         db_table = 'task_question_distributionloginlog'


# # 提交表
# class Task_sumbit(models.Model):
#     submit_id = models.AutoField(primary_key=True)                               # 提交id
#     task_id = models.IntegerField()                                 # 所属task的id
#     user = models.IntegerField()                                    # 提交者id
#     submit_time = models.DateTimeField()                            # 提交时间
#     use_time = models.IntegerField()                                # 花费时间
#     submit_content = models.TextField()                # 提交答案
#     score = models.CharField(max_length=50)                         # 各项得分
#     remask = models.TextField()                     # 备注
#     defunct = models.BooleanField()                                 # 是否失效
#     number = models.IntegerField(default=0)                                  # 题目数量
#     judge_time = models.IntegerField()                              # 判题时间
#     judge_user = models.CharField(max_length=50)                    # 判题者
#     submit_ip = models.CharField(max_length=20)                     # 提交ip

#     class Meta:
#         managed = True
#         db_table = 'task_sumbit'
